package cn.piggy.gateway.core.session.simple;

import cn.piggy.gateway.core.executor.Executor;
import cn.piggy.gateway.core.http.HttpStatement;
import cn.piggy.gateway.core.session.GatewaySession;
import java.util.Map;


public class SimpleGatewaySession implements GatewaySession {
    private final Executor executor;
    private final HttpStatement httpStatement;

    public SimpleGatewaySession(HttpStatement httpStatement, Executor executor) {
        this.executor = executor;
        this.httpStatement = httpStatement;
    }

    @Override
    public Object get(Map<String, Object> params) {
        try {
            return executor.exec(httpStatement, params);
        } catch (Exception e) {
            throw new RuntimeException("Error exec get. Cause: " + e);
        }
    }

    @Override
    public Object post(Map<String, Object> params) {
        return get(params);
    }

    @Override
    public Object put(Map<String, Object> params) {
        return get(params);
    }

    @Override
    public Object delete(Map<String, Object> params) {
        return get(params);
    }

    @Override
    public HttpStatement getHttpStatement() {
        return httpStatement;
    }

}
